2020-2021 Sunseeker Telemetry and Lighting System
eusci_a_uart_ex1_loopbackAdvanced.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
61 //******************************************************************************
62 #include "driverlib.h"
63 
64 uint16_t i;
65 uint8_t RXData = 0, TXData = 0;
66 uint8_t check = 0;
67 
68 void main(void)
69 {
70  // stop watchdog
71  WDT_A_hold(WDT_A_BASE);
72 
73  // LFXT Setup
74  //Set PJ.4 and PJ.5 as Primary Module Function Input.
75  /*
76 
77  * Select Port J
78  * Set Pin 4, 5 to input Primary Module Function, LFXT.
79  */
80  GPIO_setAsPeripheralModuleFunctionInputPin(
81  GPIO_PORT_PJ,
82  GPIO_PIN4 + GPIO_PIN5,
83  GPIO_PRIMARY_MODULE_FUNCTION
84  );
85 
86  //Set DCO frequency to 1 MHz
87  CS_setDCOFreq(CS_DCORSEL_0,CS_DCOFSEL_0);
88  //Set external clock frequency to 32.768 KHz
89  CS_setExternalClockSource(32768,0);
90  //Set ACLK=LFXT
91  CS_initClockSignal(CS_ACLK,CS_LFXTCLK_SELECT,CS_CLOCK_DIVIDER_1);
92  //Set SMCLK = DCO with frequency divider of 1
93  CS_initClockSignal(CS_SMCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_1);
94  //Set MCLK = DCO with frequency divider of 1
95  CS_initClockSignal(CS_MCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_1);
96  //Start XT1 with no time out
97  CS_turnOnLFXT(CS_LFXT_DRIVE_0);
98 
99 
100  // Configure UART pins
101  //Set P2.0 and P2.1 as Secondary Module Function Input.
102  /*
103 
104  * Select Port 2d
105  * Set Pin 0, 1 to input Secondary Module Function, (UCA0TXD/UCA0SIMO, UCA0RXD/UCA0SOMI).
106  */
107  GPIO_setAsPeripheralModuleFunctionInputPin(
108  GPIO_PORT_P2,
109  GPIO_PIN0 + GPIO_PIN1,
110  GPIO_SECONDARY_MODULE_FUNCTION
111  );
112 
113  /*
114  * Disable the GPIO power-on default high-impedance mode to activate
115  * previously configured port settings
116  */
117  PMM_unlockLPM5();
118 
119  // Configure UART
120  EUSCI_A_UART_initParam param = {0};
121  param.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_ACLK;
122  param.clockPrescalar = 3;
123  param.firstModReg = 0;
124  param.secondModReg = 92;
125  param.parity = EUSCI_A_UART_NO_PARITY;
126  param.msborLsbFirst = EUSCI_A_UART_LSB_FIRST;
127  param.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT;
128  param.uartMode = EUSCI_A_UART_MODE;
129  param.overSampling = EUSCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION;
130 
131  if (STATUS_FAIL == EUSCI_A_UART_init(EUSCI_A0_BASE, &param)) {
132  return;
133  }
134 
135  EUSCI_A_UART_enable(EUSCI_A0_BASE);
136 
137  EUSCI_A_UART_clearInterrupt(EUSCI_A0_BASE,
138  EUSCI_A_UART_RECEIVE_INTERRUPT);
139 
140  // Enable USCI_A0 RX interrupt
141  EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE,
142  EUSCI_A_UART_RECEIVE_INTERRUPT); // Enable interrupt
143 
144  __enable_interrupt();
145  while (1)
146  {
147  TXData = TXData+1; // Increment TX data
148  // Load data onto buffer
149  EUSCI_A_UART_transmitData(EUSCI_A0_BASE,
150  TXData);
151  while(check != 1);
152  check = 0;
153  }
154 }
155 //******************************************************************************
156 //
157 //This is the USCI_A0 interrupt vector service routine.
158 //
159 //******************************************************************************
160 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
161 #pragma vector=USCI_A0_VECTOR
162 __interrupt
163 #elif defined(__GNUC__)
164 __attribute__((interrupt(USCI_A0_VECTOR)))
165 #endif
166 void USCI_A0_ISR(void)
167 {
168  switch(__even_in_range(UCA0IV,USCI_UART_UCTXCPTIFG))
169  {
170  case USCI_NONE: break;
171  case USCI_UART_UCRXIFG:
172  RXData = EUSCI_A_UART_receiveData(EUSCI_A0_BASE);
173  if(!(RXData == TXData)) // Check value
174  {
175  while(1);
176  }
177  check =1;
178  break;
179  case USCI_UART_UCTXIFG: break;
180  case USCI_UART_UCSTTIFG: break;
181  case USCI_UART_UCTXCPTIFG: break;
182  }
183 }
MPU_initThreeSegmentsParam param
void USCI_A0_ISR(void)
#define STATUS_FAIL
Definition: hw_memmap.h:23